package logic

import (
	"context"
	"yk/ykrpc/ykrpc"

	"yk/api/internal/svc"
	"yk/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type YkAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewYkAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YkAddLogic {
	return &YkAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *YkAddLogic) YkAdd(req *types.YkAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.YkRpc.YkAdd(l.ctx, &ykrpc.YkAddRequest{
		Name:    req.Name,
		Num:     int64(req.Num),
		Address: req.Address,
	})
	if err != nil {
		return &types.Response{
			Message:  err.Error(),
			Code:     0,
			Database: nil,
		}, nil
	}

	return &types.Response{
		Message:  "添加成功",
		Code:     200,
		Database: add,
	}, nil
}
